﻿''' <summary>
''' 命令キー属性
''' </summary>
''' <remarks></remarks>
<AttributeUsage(AttributeTargets.Property, Allowmultiple:=False)>
Public NotInheritable Class CommandKeyAttribute
    Inherits Attribute

    ''' <summary>
    ''' コマンドテキスト読み込みイベント
    ''' </summary>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Public Shared Event OnCommandTextReading As EventHandler(Of CommandTextReadingEventArgs)

    ''' <summary>
    ''' 名前
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Name As String

    Private _commandText As String
    ''' <summary>
    ''' スカラーコマンドテキスト
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks>
    ''' SQL Server のオートナンバー事後処理 <code>SELECT @@IDENTITY</code>
    ''' SQL Server のシーケンス事前処理 <code>SELECT NEXT VALUE FOR dbo.Sequence1</code>
    ''' Oracle のシーケンス事前処理 <code>SELECT SEQ1.NEXTVAL FROM DUAL</code>
    ''' カスタム事前処理 <code>SELECT COUNT(*) + 1 FROM Table1</code>
    ''' </remarks>
    Public Property CommandText As String
        Get
            If _commandText Is Nothing OrElse String.IsNullOrEmpty(_commandText) Then
                Dim args As New CommandTextReadingEventArgs With {.Name = Me.Name, .CommandText = String.Empty}
                RaiseEvent OnCommandTextReading(Me, args)
                Return args.CommandText
            End If
            Return _commandText
        End Get
        Set(value As String)
            _commandText = value
        End Set
    End Property

    ''' <summary>
    ''' キータイプ
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property KeyType As KeyTypes = KeyTypes.Custom
End Class
